package com.jindy.module.projectcostdetails.service.impl;

import com.jindy.common.core.domain.entity.SysUser;
import com.jindy.common.utils.DateUtils;
import com.jindy.common.utils.SecurityUtils;
import com.jindy.module.projectcostdetails.domain.ProjectCostDetails;
import com.jindy.module.projectcostdetails.mapper.ProjectCostDetailsMapper;
import com.jindy.module.projectcostdetails.service.ProjectCostDetailsService;
import com.jindy.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 项目费用明细Service业务实现类
 *
 * @author zhaoxi
 * @date 2022-11-12
 */

@Service
public class ProjectCostDetailsServiceImpl implements ProjectCostDetailsService {

    @Resource
    ProjectCostDetailsMapper projectCostDetailsMapper;

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询项目费用明细列表
     *
     * @param details 物流费用
     * @return 项目费用明细列表
     */
    @Override
    public List<ProjectCostDetails> selectProjectCostDetailsList(ProjectCostDetails details) {
        return projectCostDetailsMapper.selectProjectCostDetailsList(details);
    }

    /**
     * 查询项目费用明细
     *
     * @param id 项目费用明细主键
     * @return 项目费用明细数据
     */
    @Override
    public ProjectCostDetails selectProjectCostDetailsById(String id) {
        return projectCostDetailsMapper.selectProjectCostDetailsById(id);
    }


    /**
     * 新增项目费用明细数据
     *
     * @param details 项目费用明细
     * @return 项目费用明细
     */
    @Override
    public int insertProjectCostDetails(ProjectCostDetails details)
    {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        details.setCreateBy(sysUser.getUserName());
        details.setCreateTime(DateUtils.getNowDate());
        return projectCostDetailsMapper.insertProjectCostDetails(details);
    }

    /**
     * 修改项目费用明细数据
     *
     * @param details
     * @return 结果
     */
    @Override
    public int updateProjectCostDetails(ProjectCostDetails details) {
        SysUser sysUser = sysUserService.selectUserByUserName(SecurityUtils.getUsername());
        details.setUpdateBy(sysUser.getUserName());
        details.setUpdateTime(DateUtils.getNowDate());
        return projectCostDetailsMapper.updateProjectCostDetails(details);
    }

    /**
     * 删除项目费用明细数据
     *
     * @param id 项目费用明细主键
     * @return 结果
     */
    @Override
    public int deleteProjectCostDetailsById(String id)
    {
        return projectCostDetailsMapper.deleteProjectCostDetailsById(id);
    }

    /**
     * 批量删除项目费用明细
     *
     * @param ids 需要删除的主键
     * @return 结果
     */
    @Override
    public int deleteProjectCostDetailsByIds(String[] ids)
    {
        return projectCostDetailsMapper.deleteProjectCostDetailsByIds(ids);
    }

}
